package 笔试.室友;

import java.util.Arrays;
import java.util.Scanner;

/**
 * @author:谢君臣
 * @Date:2021/7/13-16:17
 * @version:1.0
 * @function:
 */
public class gs2 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int T = in.nextInt();
        int N = in.nextInt();
        int[] t = new int[N];
        for (int i = 0; i < t.length; i++) {
            t[i] = in.nextInt();
        }
        int[] p = new int[N];
        for (int i = 0; i < p.length; i++) {
            p[i] = in.nextInt();
        }
        product[] list = new product[t.length];
        for (int i = 0; i < t.length; i++) {
            list[i] = new product(t[i],p[i]);
        }
        Arrays.sort(list);
        System.out.println(Arrays.toString(list));

        int[] res = Greedy(list,T);

    }

    private static int[] Greedy(product[] list, int t) {
        int [] res = new int[list.length];
        int i = res.length-1,bast = -1;
        while (t>0){
            if (list[i].time==t){res[i]=1;t=0;}
            else {
                if (list[i].time < t){
                    res[i]=1;
                    t= t-list[i].time;
                }
                else {
                    bast = i;
                }
            }
        }
        return res;
    }


    //使用动态 规划
    public static void dp() {
        //每个物品的重量
        int[] w = new int[]{2, 1, 3, 2};
        //每个物品的价值
        int[] v = new int[]{3, 2, 4, 2};
        int n = w.length;
        int total = 5;
        //1)状态的定义
        //     dp[i][j] --->取前i个物品在容量为j的时候所能获得的最大值
        int[][] dp = new int[n][total + 1];
        //2)初始值  //给第1行赋值
        for (int i = 0; i < dp[0].length; i++) {
            if (i >= w[0]) {
                dp[0][i] = v[0];
            } else {
                dp[0][i] = 0;
            }
        } //3状态转移方程
        for (int i = 1; i < dp.length; i++) {
            for (int j = 0; j < total + 1; j++) { //能放下
                if (j > w[i]) {
                    //选
                    int v1 = v[i] + dp[i - 1][j - w[i]];
                    //不选
                    int v2 = dp[i - 1][j];
                    dp[i][j] = Math.max(v1, v2);
                } else {
                    dp[i][j] = dp[i - 1][j];
                }
            }
        }
        System.out.println(dp[n - 1][total]);
    }
}

class product implements Comparable{
    public int time;
    public int price;
    public double value;

    public product() {
    }

    public product(int time, int price) {
        this.time = time;
        this.price = price;
        this.value = time/1.0/price;
    }
    @Override
    public int compareTo(Object o) {
        product data = (product) o;
        if (this.value> data.value) {
            return 1;
        }else if (this.value == data.value){
            return this.time - data.time;
        }else
            return -1;
    }

    @Override
    public String toString() {
        return "product{" +
                "time=" + time +
                ", price=" + price +
                ", value=" + value +
                '}';
    }
}
